package com.JZ.QM.utils;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.core.io.ClassPathResource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author cyc
 * @email cyc@gmail.com
 * @date 2020/6/24 11:37
 */
public class RiskLevelInfo {
    /**
     * 读取风险内容json文件为字符串类型
     * @return 将json返回成String形式
     */
    public static String readJson(){
        String jsonStr = "";
        try {
            InputStream inputStream= new ClassPathResource("riskInfo.json").getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = br.read()) != -1) {
                sb.append((char) ch);
            }
            br.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 将json文件读取至缓存中
     * @return 返回json对象
     */
    public static JSONObject getJson() throws JSONException {
        JSONObject json=new JSONObject(readJson());
        System.out.println(json);
        return json;
    }

}
